/**
 * 交易流水管理初始化
 */
var MchBus = {
    id: "MchBusTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
MchBus.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '商户编码', field: 'merCode', visible: true, align: 'center', valign: 'middle'},
            {title: '通道编号', field: 'chMerCode', visible: true, align: 'center', valign: 'middle'},
            {title: '业务编码', field: 'busCode', visible: true, align: 'center', valign: 'middle'},
            {title: '提现费', field: 'drawFee', visible: true, align: 'center', valign: 'middle'},
            {title: '交易费率', field: 'tradeRate', visible: true, align: 'center', valign: 'middle'},
            {title: '响应编码', field: 'resCode', visible: true, align: 'center', valign: 'middle'},
            {title: '响应描述', field: 'resMsg', visible: true, align: 'center', valign: 'middle'},
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter:"statusFormatter"}
    ];
};


function statusFormatter(value, row, index){
	if (value == 0) {
		return '<span class="label label-default">待开通</span>';
	} else if(value ==1) {
		return '<span class="label label-success">成功</span>';
	}else if(value ==2){
		return '<span class="label label-danger">失败</span>';
	}
}

/**
 * 检查是否选中
 */
MchBus.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        MchBus.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加交易流水
 */
MchBus.openAddMchBus = function () {
    var index = layer.open({
        type: 2,
        title: '添加交易流水',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/mchBus/mchBus_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看交易流水详情
 */
MchBus.openMchBusDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '交易流水详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/mchBus/mchBus_update/' + MchBus.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除交易流水
 */
MchBus.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/mchBus/delete", function (data) {
            Feng.success("删除成功!");
            MchBus.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("mchBusId",this.seItem.id);
        ajax.start();s
    }
};


/**
 * 查询参数
 */
MchBus.formParams = function() {
    var queryData = {};
    queryData['merCode'] = $("#merCode").val();
    queryData['chMerCode'] = $("#chMerCode").val();
    queryData['status'] = $("#status").val();
    return queryData;
}

/**
 * 查询交易流水列表
 */
MchBus.search = function () {
	MchBus.table.refresh({query: MchBus.formParams()});
};

$(function () {
    var defaultColunms = MchBus.initColumn();
    var table = new BSTable(MchBus.id, "/mchBus/list", defaultColunms);
    table.setPaginationType("server");//服务器端分页
    table.setQueryParams(MchBus.formParams());
    MchBus.table = table.init();
});

